// 策略模式, 根据环境类选择不同的策略类
/**
 * context
 * stragegy
 * concrete stragegy
 */

//  ABtest? canvas or webGL

interface IAB {
  run: (info:string) => string;
}

interface IContext {
  strage: IAB;
  str: string;
}

export class StragegyA implements IAB {
  run(str:string) {
    return `hello ${str}, testA`
  }
}

export class StragegyB implements IAB {
  run(str:string) {
    return `${str}, TestB`
  }
}

// 环境类
export class Context {
  // 持有一个策略类型
  private stragey: IAB;
  private str: string;
  constructor(props: IContext) {
    this.stragey = props.strage;
    this.str = props.str;
  }
  // 改变策略
  changeStragegy(stragey: IAB) {
    this.stragey = stragey;
  }
  show() {
    console.log(this.stragey.run(this.str))
  }
}